﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaseCardTypes = Wormhole.Engine.CardLibrary.BaseCardTypes;
using CardTypes = Wormhole.Engine.CardLibrary.CardTypes;

namespace Wormhole.Engine.Decks
{
	/// <author>Rodney McKay</author>
	/// <date>09 April 2008</date>
	/// <summary>
	/// A collection of mission cards.
	/// </summary>
	public class MissionCards : Deck
	{
		#region Delegates
		/// <summary>
		/// The delegate for the event that will be raised when a mission is played.
		/// </summary>
		/// <param name="mission">The mission that was played.</param>
		public delegate void MissionPlayedDelegate(CardTypes.Mission mission);
		#endregion

		#region Events
		/// <summary>
		/// This event is raised when a mission is played.
		/// </summary>
		public event MissionPlayedDelegate MissionPlayed;
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize a default instance of the class.
		/// </summary>
		public MissionCards() : base()
		{
		}

		/// <summary>
		/// Create a new deck for a specific player.
		/// </summary>
		/// <param name="player">The player the deck belongs to.</param>
		public MissionCards(Player.Player player)
			: base(player)
		{
		}
		#endregion	

		#region Set Player Events
		/// <summary>
		/// Wire up the events from other engine objects to listen for.
		/// </summary>
		protected override void SetEngineEvents()
		{
		}
		#endregion

		#region Play Mission
		/// <summary>
		/// Play the top mission from the mission pile.
		/// </summary>
		public void PlayMission()
		{
			if (this.Count > 0)
			{
				// get the top mission
				CardTypes.Mission mission = this[0] as CardTypes.Mission;

				// remove the mission
				this.Remove(mission);

				// raise the event
				this.OnMissionPlayed(mission);
			}
		}
		#endregion

		#region On Mission Played
		/// <summary>
		/// Raise the mission played event.
		/// </summary>
		/// <param name="mission">The mission that was played.</param>
		protected void OnMissionPlayed(CardTypes.Mission mission)
		{
			if (this.MissionPlayed != null)
				this.MissionPlayed(mission);
		}
		#endregion
	}
}
